import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.nio.charset.StandardCharsets;

@WebServlet("/hello")
public class HelloServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//        //改变中文乱码
//        resp.setContentType("text/html; charset=utf8");
//        resp.getWriter().write("hello word 你好");
//        //定时刷新并跳转
//        resp.setHeader("Refresh", "2;URL=http://localhost:8080/schoolnet/login.html");
////        //重定向
////        resp.sendRedirect("/schoolnet/login.html");
//        //

        //解决请求参数乱码
        resp.setContentType("text/html; charset=utf8");
        String username = req.getParameter("username");
        resp.getWriter().write(username);

//        //请求转发
//        String message = "Hello from FirstServlet!";
//        req.setAttribute("message", message);
//        RequestDispatcher dispatcher = req.getRequestDispatcher("/second");
//        dispatcher.forward(req, resp);

//        //请求包含
//        resp.setContentType("text/html; charset=utf8");
//        req.setAttribute("user", "张三");
//        RequestDispatcher dispatcher = req.getRequestDispatcher("/include");
//        dispatcher.include(req, resp);
//        resp.getWriter().print("这是主Servlet的内容。<br/>");
    }
}
